package com.java2207.group1.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java2207.group1.common.LayuiPageVo;
import com.java2207.group1.mapper.HotelMapper;
import com.java2207.group1.pojo.Hotel;
import com.java2207.group1.service.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author :xs
 * @date : 2022/7/26
 */
@Service("hotelService")
public class HotelServiceImpl implements HotelService {

   @Autowired
   private HotelMapper hotelMapper;




    @Override
    public int deleteHotel(Integer id) {
       return hotelMapper.deleteHotel(id);
    }

    @Override
    public int deleteHotelsByIds(String ids) {
        String[] arrId = ids.split(",");
        return hotelMapper.deleteHotelsByIds(arrId);
    }

    @Override
    public int addHotel(Hotel hotel) {
        return hotelMapper.addHotel(hotel);
    }


    @Override
    public int updateHotel(Hotel hotel) {
     return hotelMapper.updateHotel(hotel);
    }

    @Override
    public LayuiPageVo<Hotel> listHotel(Map<String, Object> params) {
        int page = Integer.parseInt(params.get("page")+"");

        int limit = Integer.parseInt(params.get("limit")+"");

        PageHelper.startPage(page,limit);

        List<Hotel> list = hotelMapper.listHotel(params);

        PageInfo<Hotel> studentPageInfo = new PageInfo<>(list);

        LayuiPageVo<Hotel> hotelLayuiPageVo = new LayuiPageVo<>();

        hotelLayuiPageVo.setCode(0);
        hotelLayuiPageVo.setMsg("分页列表数据");
        hotelLayuiPageVo.setCount(studentPageInfo.getTotal());
        hotelLayuiPageVo.setData(studentPageInfo.getList());

        return hotelLayuiPageVo;
    }
}
